﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using System.Collections;

namespace P2.Cuberry.Modules.Framework.LocalCuberryReport
{
    public partial class Form1 : Form
    {
        private Microsoft.Reporting.WinForms.ReportViewer reportViewer1;
        private string ReportTitle;
        private System.Windows.Forms.ComboBox FiscalYearComboBox = new System.Windows.Forms.ComboBox();
        private System.Windows.Forms.ComboBox AccountTypeComboBox = new System.Windows.Forms.ComboBox();
        private System.Windows.Forms.ComboBox MonthComboBox = new System.Windows.Forms.ComboBox();
        private System.Windows.Forms.ComboBox AccountLevelComboBox = new System.Windows.Forms.ComboBox();
        private System.Windows.Forms.CheckBox StatusOpenCheckBox = new System.Windows.Forms.CheckBox();
        private System.Windows.Forms.CheckBox StatusBookedCheckBox = new System.Windows.Forms.CheckBox();
        private System.Windows.Forms.TextBox  AccountNoTexBox = new System.Windows.Forms.TextBox();
        private System.Windows.Forms.DateTimePicker DateStartTexBox = new System.Windows.Forms.DateTimePicker();
        private System.Windows.Forms.DateTimePicker DateEndTexBox = new System.Windows.Forms.DateTimePicker();
        private System.Windows.Forms.ListBox accountNoListBox = new System.Windows.Forms.ListBox();
        private System.Windows.Forms.ComboBox accountNoComboBox = new System.Windows.Forms.ComboBox();
        private System.Windows.Forms.TextBox accountNameTextBox = new System.Windows.Forms.TextBox();
        private System.Windows.Forms.ComboBox transactionStatusCombobox = new System.Windows.Forms.ComboBox();
        private System.Windows.Forms.TextBox documentNoTextBox = new System.Windows.Forms.TextBox();
        private System.Windows.Forms.TextBox descriptionHeaderTextBox = new System.Windows.Forms.TextBox();
        private System.Windows.Forms.TextBox descriptionItemTextBox = new System.Windows.Forms.TextBox();

        private P2CuberryDataSetTableAdapters.DS1TableAdapter dataTable1TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DS1TableAdapter();
        private P2CuberryDataSetTableAdapters.DataTable3TableAdapter dataTable3TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable3TableAdapter();
        private P2CuberryDataSetTableAdapters.DataTable4TableAdapter dataTable4TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable4TableAdapter();
        private P2CuberryDataSetTableAdapters.DataTable5TableAdapter dataTable5TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable5TableAdapter();
        private P2CuberryDataSetTableAdapters.DataTable6TableAdapter dataTable6TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable6TableAdapter();
        private P2CuberryDataSetTableAdapters.DataTable7TableAdapter dataTable7TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable7TableAdapter();

        private P2CuberryDataSetTableAdapters.DataTable8TableAdapter dataTable8TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable8TableAdapter();
        private P2CuberryDataSetTableAdapters.DataTable9TableAdapter dataTable9TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable9TableAdapter();
        private P2CuberryDataSetTableAdapters.DataTable10TableAdapter dataTable10TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable10TableAdapter();

        private P2CuberryDataSetTableAdapters.fiRepGetFiTransactionsRangeTableAdapter dataTable0701TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.fiRepGetFiTransactionsRangeTableAdapter();
        private P2CuberryDataSetTableAdapters.FiTransactionTotalBeforeXTableAdapter dataTable07012TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiTransactionTotalBeforeXTableAdapter();
        private P2CuberryDataSetTableAdapters.FiTransactionTotalUntilEndDateTableAdapter dataTable07013TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiTransactionTotalUntilEndDateTableAdapter();
        private P2CuberryDataSetTableAdapters.FiTransactionTotalThisYearTableAdapter dataTable07014TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiTransactionTotalThisYearTableAdapter();

        private P2CuberryDataSetTableAdapters.fiRepGetFiTransactionsRange02TableAdapter dataTable0702TableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.fiRepGetFiTransactionsRange02TableAdapter();

        private P2CuberryDataSetTableAdapters.FiAccountStatementAccountRangeTableAdapter fiAccountStatementAccountRangeTableAdapter = new P2CuberryDataSetTableAdapters.FiAccountStatementAccountRangeTableAdapter();
        private P2CuberryDataSetTableAdapters.FiAccountStatementGroupByMonthDataTableTableAdapter fiAccountStatementGroupByMonthDataTableTableAdapter = new P2CuberryDataSetTableAdapters.FiAccountStatementGroupByMonthDataTableTableAdapter();
        private P2CuberryDataSetTableAdapters.JournalOneAccountDataTableTableAdapter journalOneAccountDataTableTableAdapter = new P2CuberryDataSetTableAdapters.JournalOneAccountDataTableTableAdapter();
        private P2CuberryDataSetTableAdapters.JournalAllAccountsRangeGroupedDataTableTableAdapter journalAllAccountsRangeGroupedDataTableTableAdapter = new P2CuberryDataSetTableAdapters.JournalAllAccountsRangeGroupedDataTableTableAdapter();
        private P2CuberryDataSetTableAdapters.JournalAllAccountsRangeDataTableTableAdapter journalAllAccountsRangeDataTableTableAdapter = new P2CuberryDataSetTableAdapters.JournalAllAccountsRangeDataTableTableAdapter();
        private P2CuberryDataSetTableAdapters.JournalTransactionHeaderGroupedDataTableTableAdapter journalTransactionHeaderGroupedDataTableTableAdapter = new P2CuberryDataSetTableAdapters.JournalTransactionHeaderGroupedDataTableTableAdapter();


        public Form1()
        {
            InitializeComponent();
            this.reportViewer1.LocalReport.EnableHyperlinks = true;
            //this.reportViewer1.Drillthrough += new Microsoft.Reporting.WinForms.DrillthroughEventHandler(this.reportViewer_Drillthrough);
           
        }

        //private void reportViewer1_Hyperlink(object sender, Microsoft.Reporting.WinForms.HyperlinkEventArgs e)
        //{
        //    MessageBox.Show("asdf");
        //}

        protected void Page_Load(object sender, EventArgs e) 
        {             
                this.reportViewer1.LocalReport.EnableHyperlinks = true;                
        }

        

        public Form1(string repTitle)
        {
            InitializeComponent();            
            ReportTitle = repTitle;
            // reportViewer1/////////////////            
            this.reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer();
            this.reportViewer1.ProcessingMode = ProcessingMode.Local;

            this.reportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.reportViewer1.Location = new System.Drawing.Point(0, 0);
            this.reportViewer1.Name = "reportViewer1";
            this.reportViewer1.Size = new System.Drawing.Size(861, 447);
            this.reportViewer1.TabIndex = 0;

            this.splitContainer1.Panel2.Controls.Add(this.reportViewer1);
            // reportViewer1/////////////////

            switch (ReportTitle)
            {
                case "01 Chart of Accounts":
                    InitReport01();
                    break;

                case "Report1":
                    InitReport02();
                    break;


                case "02 Profit and Loss One Year":
                    InitReport03();
                    break;

                case "02 Profit and Loss Year to Month":
                    InitReport04();
                    break;

                case "0301 Trial Balance One Year":
                    InitReport05(false);
                    break;

                case "0302 Trial Balance One Year General":
                    InitReport05(false); //it's using the same base
                    break;

                case "0303 Trial Balance One Year One Level":
                    InitReport05(true); //it's using the same basis, but with parameter AccountNo
                    break;

                case "0304 Trial Balance Year to Month":
                    InitReport06(false); 
                    break;

                case "0305 Trial Balance Year to Month General":
                    InitReport06(false); //it's using the same base
                    break;
                    

                case "0306 Trial Balance Year to Month One Level":
                    InitReport06(true); //it's using the same base
                    break;

                case "04 Balance Sheet One Year":
                    InitReport07();
                    // Add a handler for drillthrough.
                    reportViewer1.Drillthrough += new DrillthroughEventHandler(DrillthroughEventHandlerR08);
                    break;

                case "04 Balance Sheet Year to Month Account Type":
                    InitReport08(); 
                    break;

                case "04 Balance Sheet Year to Month":
                    InitReport09(); 
                    break;

                case "05 Account Statement Account Range II":
                    InitReport10(); 
                    break;         
               
                case "05 Account Statement Account Range":
                    InitReport05AccountRange(true);
                    break;

                case "05 Account Statement Grouped by Month":
                    InitReport05AccountStatementGroupeBbyMonth();
                    break;

                case "06 General Ledger Accounts Overview Account Range":
                    InitReport05AccountRange(true);
                    break;

                case "06 General Ledger All Accounts Overview":
                    InitReport05AccountRange(false);
                    break;

                case "0701 Journal One Account II":
                    InitReport0701(); 
                    break;

                case "0702 Journal All Accounts Range Grouped II":
                    InitReport0702(); 
                    break; 

                case "0704 Journal One Account":
                    this.InitReport0704();
                    break;

                case "0705 Journal All Accounts Range Grouped":
                    this.InitReport0705();
                    break;

                case "0706 Journal All Accounts Range":
                    this.InitReport0706();
                    break;

                case "0707 Journal Transaction Header Grouped":
                    this.InitReport0707();
                    break;
            }
        }


        private void Form1_Load(object sender, EventArgs e)
        {
           
        }


  

        private void ReportRun_Click(object sender, EventArgs e)
        {

            switch (ReportTitle)
            {
                case "01 Chart of Accounts":
                    RunReport01();
                                        ReportParameter[] parameters = new ReportParameter[2];
                                        parameters[0] = new ReportParameter("FiAccountFiscalYearID", this.FiscalYearComboBox.SelectedValue.ToString());
                                        //parameters[1] = new ReportParameter("CustomerID", new string[] { "14335", "15094" });            

                                        reportViewer1.LocalReport.SetParameters(parameters);
                    
                    ////                    dsXBindingSource.DataMember = "DS1";
                    ////                    dsXBindingSource.DataSource = this.P2CuberryDataSet;

                    ////                    reportDataSourceQX.Name = "DS1";
                    ////                    reportDataSourceQX.Value = dsXBindingSource;
                    ////                    reportViewer1.LocalReport.DataSources.Add(reportDataSourceQX);
                                                            
                    ////                    P2CuberryDataSetTableAdapters.DS1TableAdapter adapter = new P2CuberryDataSetTableAdapters.DS1TableAdapter();
                    ////                    P2CuberryDataSet.DS1DataTable table = adapter.GetData(5);
                    ////                    //new ReportDataSource("DS1", table);
                    ////                    //reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DS1", table));

                    ////                    this.dataTable1TableAdapter.Fill(table, 5);

                    ////                    reportViewer1.RefreshReport();
                    //////                    this.dataTable1TableAdapter.GetData(parameters[0]);
                                       

                    //OrderTableAdapter orderAdapter = new Entities.SalesOrderTableAdapters.OrderTableAdapter();
                    //SalesOrder.OrderDataTable orderTable = orderAdapter.GetData(localReport.OriginalParametersToDrillthrough[0].Values[0]);
                    
                    break;

                case "Report1":
                    RunReport02(); 
                    break;

                case "02 Profit and Loss One Year":
                    RunReport03(); 
                    break;

                case "02 Profit and Loss Year to Month":
                    RunReport04(); 
                    break;

                case "0301 Trial Balance One Year":
                    RunReport05(false);
                    break;

                case "0302 Trial Balance One Year General":
                    RunReport05(false);
                    break;

                case "0303 Trial Balance One Year One Level":
                    RunReport05(true);
                    break;
                    
                case "0304 Trial Balance Year to Month":
                    RunReport06(false);
                    break;

                case "0305 Trial Balance Year to Month General":
                    RunReport06(false);
                    break;

                case "0306 Trial Balance Year to Month One Level":
                    RunReport06(true);
                    break;

                case "04 Balance Sheet One Year":                    
                    RunReport07();
                    break;
                    
                case "04 Balance Sheet Year to Month Account Type":
                    RunReport08();
                    break;

                case "04 Balance Sheet Year to Month":
                    RunReport09();
                    break;

                case "05 Account Statement Account Range II":
                    RunReport10();
                    break;

                case "05 Account Statement Account Range":
                    RunReport05AccountRange(true);
                    break;

                case "05 Account Statement Grouped by Month":
                    RunReport05AccountStatementGroupByMonth();
                    break;

                case "06 General Ledger Accounts Overview Account Range":
                    RunReport05AccountRange(true);
                    break;

                case "06 General Ledger All Accounts Overview":
                    Run06GeneralLedgerAllAccountsOverview();
                    break;

                case "0701 Journal One Account II":
                    RunReport0701();
                    break;

                case "0702 Journal All Accounts Range Grouped II":
                    RunReport0702();
                    break;

                case "0704 Journal One Account":
                    this.RunReport0704();
                    break;

                case "0705 Journal All Accounts Range Grouped":
                    RunReport0705();
                    break;

                case "0706 Journal All Accounts Range":
                    this.RunReport0706();
                    break;

                case "0707 Journal Transaction Header Grouped":
                    this.RunReport0707();
                    break;

                default:
                    if (ReportTitle == null)
                    {
                        MessageBox.Show ("Report not found");
                        //messageStack.Add(new P2TransactionMessage(this.ValidationType, P2Translator.GetResource("Validation_NotOK_FieldsAreNotEqual")));
                    }
                    break;
            }

            this.reportViewer1.RefreshReport();
        }



        private void ReportClear_Click(object sender, EventArgs e)
        {
            switch (ReportTitle)
            {
                case "01 Chart of Accounts":
                    this.FiscalYearComboBox.SelectedItem = null;                        
                    break;

                case "02 Profit and Loss One Year":
                    this.FiscalYearComboBox.SelectedItem = null;
                    break;

                case "02 Profit and Loss Year to Month":
                    this.FiscalYearComboBox.SelectedItem = null;
                    break;

                case "05 Account Statement Account Range":
                    this.FiscalYearComboBox.SelectedItem = null;
                    break;

                //default:
                //    if ((objValue1.ToString()) != (objValue2.ToString()))
                //    {
                //        messageStack.Add(new P2TransactionMessage(this.ValidationType, P2Translator.GetResource("Validation_NotOK_FieldsAreNotEqual")));
                //    }
                //    break;
            }
        }


        #region Run Report

        private void RunReport01()
        {
            if (this.FiscalYearComboBox.SelectedValue != null)
                this.dataTable1TableAdapter.Fill(this.P2CuberryDataSet.DS1, Convert.ToInt32(this.FiscalYearComboBox.SelectedValue.ToString()));
        }

        private void RunReport02()
        {
            //this.ccBedTableAdapter.Fill(this.P2CuberryDataSet.CCBed);  
        }

        private void RunReport03()
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);

            if (this.FiscalYearComboBox.SelectedValue != null)
            {
                this.dataTable3TableAdapter.Fill(this.P2CuberryDataSet.DataTable3, Convert.ToInt32(this.FiscalYearComboBox.SelectedValue.ToString()), statusOpen, statusBooked);
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem));
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { fyParameter });
            }
        }

        private void RunReport04()
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);
            int bookingMonth = (int)this.MonthComboBox.SelectedValue;
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);

            if (this.FiscalYearComboBox.SelectedValue != null)
            {
                this.dataTable4TableAdapter.Fill(this.P2CuberryDataSet.DataTable4, fiscalYear, bookingMonth, statusOpen, statusBooked);
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem));
                ReportParameter monthParameter = new ReportParameter("ParameterMonth", this.MonthComboBox.SelectedValue.ToString());
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { fyParameter, monthParameter });
            }
        }

        private void RunReport05(bool withAccountNo)
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);
            int accountLevel = Convert.ToInt16(this.AccountLevelComboBox.SelectedValue);
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            string accountNo = this.AccountNoTexBox.Text;

            if (this.FiscalYearComboBox.SelectedValue != null)
            {
                if (withAccountNo)
                {
                    this.dataTable5TableAdapter.FillByAccountNo(this.P2CuberryDataSet.DataTable5, accountNo, fiscalYear, accountLevel, statusOpen, statusBooked);                    
                }
                else
                {
                    this.dataTable5TableAdapter.Fill(this.P2CuberryDataSet.DataTable5, fiscalYear, accountLevel, statusOpen, statusBooked);                    
                }
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem));
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { fyParameter });

            }
        }

        private void RunReport06(bool withAccountNo)
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);
            int accountLevel = Convert.ToInt16(this.AccountLevelComboBox.SelectedValue);
            int bookingMonth = (int)this.MonthComboBox.SelectedValue;
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            string accountNo = this.AccountNoTexBox.Text;

            if (this.FiscalYearComboBox.SelectedValue != null)
            {
                if (withAccountNo)
                {
                    this.dataTable6TableAdapter.FillByAccountNo(this.P2CuberryDataSet.DataTable6, accountNo, fiscalYear, bookingMonth, accountLevel, statusOpen, statusBooked);
                }
                else
                {
                    this.dataTable6TableAdapter.Fill(this.P2CuberryDataSet.DataTable6, fiscalYear, bookingMonth, accountLevel, statusOpen, statusBooked);
                }

                string xParentAccount = this.dataTable6TableAdapter.FindAccountFromNumber(accountNo, fiscalYear);
                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem));
                ReportParameter monthParameter = new ReportParameter("ParameterMonth", this.MonthComboBox.SelectedValue.ToString());
                ReportParameter parentAccountParameter = new ReportParameter("ParameterParentAccount", xParentAccount);
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { fyParameter, monthParameter, parentAccountParameter });

            }
        }

        private void RunReport07()
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);
            //int accountLevel = Convert.ToInt16(this.AccountLevelComboBox.SelectedValue);
            //int bookingMonth = (int)this.MonthComboBox.SelectedValue;
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            //string accountNo = this.AccountNoTexBox.Text;

            if (this.FiscalYearComboBox.SelectedValue != null)
            {
                
                this.dataTable7TableAdapter.Fill(this.P2CuberryDataSet.DataTable7, fiscalYear, statusOpen, statusBooked);                

                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem));                
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { fyParameter });                
            }
        }
        
        private void RunReport08()
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);
            int accountLevel = Convert.ToInt16(this.AccountLevelComboBox.SelectedValue);
            int bookingMonth = (int)this.MonthComboBox.SelectedValue;
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            int accountType = Convert.ToInt32(this.AccountTypeComboBox.SelectedValue);

            if (this.FiscalYearComboBox.SelectedValue != null)
            {

                this.dataTable8TableAdapter.Fill(this.P2CuberryDataSet.DataTable8, accountType, fiscalYear, bookingMonth, accountLevel, statusOpen, statusBooked);

                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem));
                ReportParameter monthParameter = new ReportParameter("ParameterMonth", this.MonthComboBox.SelectedValue.ToString());
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { fyParameter, monthParameter });
            }
        }

        private void RunReport09()
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);            
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            int bookingMonth = (int)this.MonthComboBox.SelectedValue;

            if (this.FiscalYearComboBox.SelectedValue != null)
            {
                this.dataTable9TableAdapter.Fill(this.P2CuberryDataSet.DataTable9,  fiscalYear, bookingMonth, statusOpen, statusBooked);

                ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem));
                ReportParameter monthParameter = new ReportParameter("ParameterMonth", this.MonthComboBox.SelectedValue.ToString());
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { fyParameter, monthParameter });
            }
        }

        private void RunReport10()
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            //int bookingMonth = (int)this.MonthComboBox.SelectedValue;
            string accountNo = this.AccountNoTexBox.Text;
                        
            DateTime dateStart = this.DateStartTexBox.Value.Date;
            DateTime dateEnd = this.DateEndTexBox.Value.Date;
            DateTime fyDateStart = this.DateStartTexBox.Value.Date;
            DateTime fyDateEnd = this.DateEndTexBox.Value.Date;  

            if (this.FiscalYearComboBox.SelectedValue != null)
            {
                this.dataTable10TableAdapter.Fill(this.P2CuberryDataSet.DataTable10, fiscalYear, dateStart, dateEnd, accountNo, fyDateStart);
                
                ReportParameter dateStartFYParameter = new ReportParameter("ParameterFYDateStart", fyDateStart.ToString());
                ReportParameter dateEndFYParameter = new ReportParameter("ParameterFYDateEnd", fyDateEnd.ToString());

                ReportParameter dateStartParameter = new ReportParameter("ParameterDateStart", dateStart.ToString());
                ReportParameter dateEndParameter = new ReportParameter("ParameterDateEnd", dateEnd.ToString());
                                
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { dateStartParameter, dateEndParameter, dateStartFYParameter, dateEndFYParameter });
            }
        }

        private void RunReport05AccountRange(bool withAccountNo)
        {
            if (this.FiscalYearComboBox.SelectedValue == null)
                return;

            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            string accountNo = this.AccountNoTexBox.Text.Trim();
            DateTime dateStart = this.DateStartTexBox.Value;
            DateTime dateEnd = this.DateEndTexBox.Value;
            
            if (withAccountNo)
            {
                
                this.fiAccountStatementAccountRangeTableAdapter.ClearBeforeFill = true;
                this.P2CuberryDataSet.FiAccountStatementAccountRangeDataTable.DataSet.EnforceConstraints = false;
                this.fiAccountStatementAccountRangeTableAdapter.Fill(this.P2CuberryDataSet.FiAccountStatementAccountRangeDataTable, 
                                                                        fiscalYear, 
                                                                        dateStart.Date, 
                                                                        dateEnd.Date, 
                                                                        accountNo);
            }
            else
            {

            }
        }

        private void RunReport05AccountStatementGroupByMonth()
        {
            if (this.FiscalYearComboBox.SelectedValue == null)
                return;

            if (this.accountNoListBox.SelectedItems.Count == 0)
                return;

            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            int fiAccountNo = Convert.ToInt32(accountNoListBox.SelectedValue.ToString());
            DateTime dateStart = this.DateStartTexBox.Value;
            DateTime dateEnd = this.DateEndTexBox.Value;

            this.fiAccountStatementGroupByMonthDataTableTableAdapter.ClearBeforeFill = true;
            this.P2CuberryDataSet.FiAccountStatementGroupByMonthDataTable.DataSet.EnforceConstraints = false;
            this.fiAccountStatementGroupByMonthDataTableTableAdapter.Fill(this.P2CuberryDataSet.FiAccountStatementGroupByMonthDataTable, fiscalYear, fiAccountNo, dateStart, dateEnd);
        }

        private void Run06GeneralLedgerAllAccountsOverview()
        {
             if (this.FiscalYearComboBox.SelectedValue == null)
                return;

            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            DateTime dateStart = this.DateStartTexBox.Value;
            DateTime dateEnd = this.DateEndTexBox.Value;
                
            this.fiAccountStatementAccountRangeTableAdapter.ClearBeforeFill = true;
            this.P2CuberryDataSet.FiAccountStatementAccountRangeDataTable.DataSet.EnforceConstraints = false;
            this.fiAccountStatementAccountRangeTableAdapter.FillByFiscalYear(this.P2CuberryDataSet.FiAccountStatementAccountRangeDataTable, 
                                                                    fiscalYear, 
                                                                    dateStart.Date, 
                                                                    dateEnd.Date);

        }

        private void RunReport0701()
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            //int bookingMonth = (int)this.MonthComboBox.SelectedValue;            
            string accountNo = this.accountNoComboBox.SelectedValue.ToString();

            DateTime dateStart = this.DateStartTexBox.Value.Date;
            DateTime dateEnd = this.DateEndTexBox.Value.Date;
            DateTime fyDateStart = this.DateStartTexBox.Value.Date;
            DateTime fyDateEnd = this.DateEndTexBox.Value.Date;  


            if (this.FiscalYearComboBox.SelectedValue != null)
            {
                this.dataTable0701TableAdapter.Fill(this.P2CuberryDataSet.fiRepGetFiTransactionsRange, fiscalYear, dateStart, dateEnd, accountNo);
                this.dataTable07012TableAdapter.Fill(this.P2CuberryDataSet.FiTransactionTotalBeforeX, fiscalYear, dateStart, accountNo);
                this.dataTable07013TableAdapter.Fill(this.P2CuberryDataSet.FiTransactionTotalUntilEndDate, fiscalYear, dateStart,dateEnd, accountNo);
                this.dataTable07014TableAdapter.Fill(this.P2CuberryDataSet.FiTransactionTotalThisYear, fiscalYear, dateStart, dateEnd, accountNo);

                if (this.FiscalYearComboBox.SelectedIndex > -1)
                {
                    DataRowView row = (DataRowView)this.FiscalYearComboBox.SelectedItem;
                    fyDateStart = Convert.ToDateTime(row[2]);
                    fyDateEnd = Convert.ToDateTime(row[3]);                                                       
                }

                ReportParameter dateStartFYParameter = new ReportParameter("ParameterFYDateStart", fyDateStart.ToString());
                ReportParameter dateEndFYParameter = new ReportParameter("ParameterFYDateEnd", fyDateEnd.ToString()); 

                ReportParameter dateStartParameter = new ReportParameter("ParameterDateStart", dateStart.ToString());
                ReportParameter dateEndParameter = new ReportParameter("ParameterDateEnd", dateEnd.ToString());

                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { dateStartParameter, dateEndParameter, dateStartFYParameter, dateEndFYParameter });
                //this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { dateStartParameter, dateEndParameter});
            }
        }

        private void RunReport0702()
        {
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            //int bookingMonth = (int)this.MonthComboBox.SelectedValue;
            string accountNo = this.AccountNoTexBox.Text;

            DateTime dateStart = this.DateStartTexBox.Value.Date;
            DateTime dateEnd = this.DateEndTexBox.Value.Date;
            DateTime fyDateStart = this.DateStartTexBox.Value.Date;
            DateTime fyDateEnd = this.DateEndTexBox.Value.Date;


            if (this.FiscalYearComboBox.SelectedValue != null)
            {
                this.dataTable0702TableAdapter.Fill(this.P2CuberryDataSet.fiRepGetFiTransactionsRange02, fiscalYear, dateStart, dateEnd, accountNo);
                //this.dataTable07012TableAdapter.Fill(this.P2CuberryDataSet.FiTransactionTotalBeforeX, fiscalYear, dateStart, accountNo);
                //this.dataTable07013TableAdapter.Fill(this.P2CuberryDataSet.FiTransactionTotalUntilEndDate, fiscalYear, dateStart, dateEnd, accountNo);
                //this.dataTable07024TableAdapter.Fill(this.P2CuberryDataSet.FiTransactionTotalThisYear02, fiscalYear, dateStart, dateEnd, accountNo);

                if (this.FiscalYearComboBox.SelectedIndex > -1)
                {
                    DataRowView row = (DataRowView)this.FiscalYearComboBox.SelectedItem;
                    fyDateStart = Convert.ToDateTime(row[2]);
                    fyDateEnd = Convert.ToDateTime(row[3]);
                }

                ReportParameter dateStartFYParameter = new ReportParameter("ParameterFYDateStart", fyDateStart.ToString());
                ReportParameter dateEndFYParameter = new ReportParameter("ParameterFYDateEnd", fyDateEnd.ToString());

                ReportParameter dateStartParameter = new ReportParameter("ParameterDateStart", dateStart.ToString());
                ReportParameter dateEndParameter = new ReportParameter("ParameterDateEnd", dateEnd.ToString());

                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { dateStartParameter, dateEndParameter, dateStartFYParameter, dateEndFYParameter });
                //this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { dateStartParameter, dateEndParameter});
            }
        }

        private void RunReport0704()
        {

            if (this.FiscalYearComboBox.SelectedValue == null)
                return;

            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            int tranSatatus = Convert.ToInt32(this.transactionStatusCombobox.SelectedValue);
            string accountNo = this.accountNoComboBox.SelectedValue.ToString();
            DateTime dateStart = this.DateStartTexBox.Value;
            DateTime dateEnd = this.DateEndTexBox.Value;

            this.journalOneAccountDataTableTableAdapter.ClearBeforeFill = true;
            this.P2CuberryDataSet.JournalOneAccountDataTable.DataSet.EnforceConstraints = false;
            this.journalOneAccountDataTableTableAdapter.Fill(this.P2CuberryDataSet.JournalOneAccountDataTable, fiscalYear, dateStart, dateEnd, accountNo, tranSatatus);
        }

        private void RunReport0705()
        {

            if (this.FiscalYearComboBox.SelectedValue == null)
                return;

            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            int tranStatus = Convert.ToInt32(this.transactionStatusCombobox.SelectedValue);
            string accountNo = this.AccountNoTexBox.Text.Trim();
            DateTime dateStart = this.DateStartTexBox.Value;
            DateTime dateEnd = this.DateEndTexBox.Value;

            this.journalAllAccountsRangeGroupedDataTableTableAdapter.ClearBeforeFill = true;
            this.P2CuberryDataSet.JournalAllAccountsRangeGroupedDataTable.DataSet.EnforceConstraints = false;
            this.journalAllAccountsRangeGroupedDataTableTableAdapter.Fill(this.P2CuberryDataSet.JournalAllAccountsRangeGroupedDataTable, fiscalYear, dateStart, dateEnd, accountNo, tranStatus);
        }

        private void RunReport0706()
        {

            if (this.FiscalYearComboBox.SelectedValue == null)
                return;

            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            int tranStatus = Convert.ToInt32(this.transactionStatusCombobox.SelectedValue);
            string accountNo = this.AccountNoTexBox.Text.Trim();
            DateTime dateStart = this.DateStartTexBox.Value;
            DateTime dateEnd = this.DateEndTexBox.Value;

            this.journalAllAccountsRangeDataTableTableAdapter.ClearBeforeFill = true;
            this.P2CuberryDataSet.JournalAllAccountsRangeDataTable.DataSet.EnforceConstraints = false;
            this.journalAllAccountsRangeDataTableTableAdapter.Fill(this.P2CuberryDataSet.JournalAllAccountsRangeDataTable, fiscalYear, dateStart, dateEnd, accountNo, tranStatus);
        }

        private void RunReport0707()
        {

            if (this.FiscalYearComboBox.SelectedValue == null)
                return;

            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);
            DateTime dateStart = this.DateStartTexBox.Value;
            DateTime dateEnd = this.DateEndTexBox.Value;

            this.journalTransactionHeaderGroupedDataTableTableAdapter.ClearBeforeFill = true;
            this.P2CuberryDataSet.JournalTransactionHeaderGroupedDataTable.DataSet.EnforceConstraints = false;

            if (string.IsNullOrEmpty(documentNoTextBox.Text) && string.IsNullOrEmpty(descriptionHeaderTextBox.Text) && string.IsNullOrEmpty(descriptionItemTextBox.Text))
            {
                this.journalTransactionHeaderGroupedDataTableTableAdapter.FillByFiscalYear(this.P2CuberryDataSet.JournalTransactionHeaderGroupedDataTable,
                                                                               fiscalYear,
                                                                               dateStart,
                                                                               dateEnd);
            }
            else
            {
                this.journalTransactionHeaderGroupedDataTableTableAdapter.Fill(this.P2CuberryDataSet.JournalTransactionHeaderGroupedDataTable,
                                                                                fiscalYear,
                                                                                dateStart,
                                                                                dateEnd,
                                                                                documentNoTextBox.Text.Trim(),
                                                                                descriptionHeaderTextBox.Text.Trim(),
                                                                                descriptionItemTextBox.Text.Trim());
            }
        }

        #endregion



        #region Report Initialization & Loading

        public void InitReport01()
        {
            P2CuberryDataSetTableAdapters.DS1TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DS1TableAdapter();                     
            this.SuspendLayout();

            //initialize Report
            initReportDS("DS1", "DS1");
            dsXTableAdapter.ClearBeforeFill = true;

            // Add controls
            addControlFiscalYear();
                                 
            this.ResumeLayout(false);            
            loadReport();            
        }

        public void InitReport02()
        {
            //P2CuberryDataSetTableAdapters.CCBedTableAdapter dsXTableAdapter = new ReportViewer.P2CuberryDataSetTableAdapters.CCBedTableAdapter();              
            //this.SuspendLayout();

            ////initialize Report
            //initReportDS("CCBed", "CCBed");
            //dsXTableAdapter.ClearBeforeFill = true; 
            
            //this.ResumeLayout(false);
            ////loadReport();
            //this.reportViewer1.LocalReport.ReportEmbeddedResource = "ReportViewer." + this.ReportTitle + ".rdlc";
        }

        public void InitReport03()
        {
            P2CuberryDataSetTableAdapters.DataTable3TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable3TableAdapter();            
            this.SuspendLayout();

            //initialize Report
            initReportDS("DataTable3", "DataTable3");
            dsXTableAdapter.ClearBeforeFill = true; 

            // Add controls
            addControlFiscalYear();
            addControlStatusOpen();
            addControlStatusBooked();            

            this.ResumeLayout(false);
            loadReport();
            //this.reportViewer1.LocalReport.ReportEmbeddedResource = @"ReportViewer.Reports." + this.ReportTitle + ".rdlc";            
        }

        public void InitReport04()
        {
            P2CuberryDataSetTableAdapters.DataTable4TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable4TableAdapter();            
            this.SuspendLayout();

            //initialize Report
            initReportDS("DataTable4", "DataTable4");                      
            dsXTableAdapter.ClearBeforeFill = true;   
            
            // Add controls
            addControlFiscalYear();     
            addControlStatusOpen();            
            addControlStatusBooked();            
            addControlMonthComboBox();  
                        
            this.ResumeLayout(false);            
            this.MonthComboBox.Text = DateTime.Today.Month.ToString();
            loadReport();
            //this.reportViewer1.LocalReport.ReportEmbeddedResource = @"ReportViewer.Reports." + this.ReportTitle + ".rdlc";
        }

        public void InitReport05(bool withAccountNo)
        {
            P2CuberryDataSetTableAdapters.DataTable5TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable5TableAdapter();
            this.SuspendLayout();

            //initialize Report
            initReportDS("DataTable5", "DataTable5");
            dsXTableAdapter.ClearBeforeFill = true;

            // Add controls
            addControlFiscalYear();
            addControlStatusOpen();
            addControlStatusBooked();
            addControlAccountLevelComboBox(5); //todo: here we have to get the max level from the ConfigTable
            if (withAccountNo)
                addControlAccountNoTexBox();
            
            this.ResumeLayout(false);            
            loadReport();            
        }

        public void InitReport06(bool withAccountNo)
        {
            P2CuberryDataSetTableAdapters.DataTable6TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable6TableAdapter();
            this.SuspendLayout();

            //initialize Report
            initReportDS("DataTable6", "DataTable6");
            dsXTableAdapter.ClearBeforeFill = true;

            // Add controls
            addControlFiscalYear();
            addControlMonthComboBox();
            addControlStatusOpen();
            addControlStatusBooked();
            addControlAccountLevelComboBox(5); //todo: here we have to get the max level from the ConfigTable
            if (withAccountNo)
                addControlAccountNoTexBox();

            this.ResumeLayout(false);
            this.MonthComboBox.Text = DateTime.Today.Month.ToString();
            loadReport();            
        }

        public void InitReport05AccountRange(bool accountNo)
        {
            P2CuberryDataSetTableAdapters.FiAccountStatementAccountRangeTableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiAccountStatementAccountRangeTableAdapter();
            this.SuspendLayout();

            //initialize Report
            initReportDS("FiAccountStatementAccountRangeDataTable", "FiAccountStatementAccountRangeDataTable");
            dsXTableAdapter.ClearBeforeFill = true;

            // Add controls
            addControlFiscalYear();            
            addControlDateStart();
            addControlDateEnd();

            if (accountNo)
                addControlAccountNoTexBox();

            this.ResumeLayout(false);

            loadReport();
        }

        public void InitReport05AccountStatementGroupeBbyMonth()
        {
            this.SuspendLayout();

            //initialize Report
            initReportDS("FiAccountStatementGroupByMonthDataTable", "FiAccountStatementGroupByMonthDataTable");

            // Add controls
            addControlFiscalYear();
            addControlAccountNoListbox();
            addControlDateStart();
            addControlDateEnd();

            FiscalYearComboBox.SelectedIndexChanged += new EventHandler(OnFiscalYearChangedUpdateAccountNoListBox);

            OnFiscalYearChangedUpdateAccountNoListBox(this, null);

            this.ResumeLayout(false);

            loadReport();
        }

        public void InitReport07()
        {
            P2CuberryDataSetTableAdapters.DataTable7TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable7TableAdapter();
            this.SuspendLayout();

            //initialize Report
            initReportDS("DataTable7", "DataTable7");
            dsXTableAdapter.ClearBeforeFill = true;

            

            //initialize Sub Report
            P2CuberryDataSetTableAdapters.DS1TableAdapter dsXTableAdapter2 = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DS1TableAdapter();            
            initReportDS2("DS1", "DS1");
            dsXTableAdapter2.ClearBeforeFill = true;


            // Add controls
            addControlFiscalYear();            
            addControlStatusOpen();
            addControlStatusBooked();

            //addControlMonthComboBox();
            //addControlAccountLevelComboBox(5); //todo: here we have to get the max level from the ConfigTable
            //if (withAccountNo)
            //    addControlAccountNoTexBox();

            this.ResumeLayout(false);
            
            loadReport();
        }

        public void InitReport08()
        {
            P2CuberryDataSetTableAdapters.DataTable8TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable8TableAdapter();
            this.SuspendLayout();

            //initialize Report
            initReportDS("DataTable8", "DataTable8");
            dsXTableAdapter.ClearBeforeFill = true;

            // Add controls
            addControlFiscalYear();
            addControlStatusOpen();
            addControlStatusBooked();
            addControlMonthComboBox();
            addControlAccountLevelComboBox(5); //todo: here we have to get the max level from the ConfigTable
            addControlAccountType();
            //if (withAccountNo)
            //    addControlAccountNoTexBox();

            this.ResumeLayout(false);

            loadReport();
        }

        public void InitReport09()
        {
            P2CuberryDataSetTableAdapters.DataTable9TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable9TableAdapter();
            this.SuspendLayout();

            //initialize Report
            initReportDS("DataTable9", "DataTable9");
            dsXTableAdapter.ClearBeforeFill = true;

            // Add controls
            addControlFiscalYear();
            addControlMonthComboBox();
            addControlStatusOpen();
            addControlStatusBooked();
            
            this.ResumeLayout(false);

            loadReport();
        }

        public void InitReport10()
        {
            P2CuberryDataSetTableAdapters.DataTable10TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.DataTable10TableAdapter();
            this.SuspendLayout();

            //initialize Report
            initReportDS("DataTable10", "DataTable10");
            dsXTableAdapter.ClearBeforeFill = true;

            // Add controls
            addControlFiscalYear();            
            addControlAccountNoTexBox();
            addControlDateStart();
            addControlDateEnd();            
            
            this.ResumeLayout(false);

            loadReport();
        }

        public void InitReport0701()
        {
            P2CuberryDataSetTableAdapters.fiRepGetFiTransactionsRangeTableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.fiRepGetFiTransactionsRangeTableAdapter();
            P2CuberryDataSetTableAdapters.FiTransactionTotalBeforeXTableAdapter dsXTableAdapter2 = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiTransactionTotalBeforeXTableAdapter();

            P2CuberryDataSetTableAdapters.FiTransactionTotalUntilEndDateTableAdapter dsXTableAdapter3 = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiTransactionTotalUntilEndDateTableAdapter();
            P2CuberryDataSetTableAdapters.FiTransactionTotalThisYearTableAdapter dsXTableAdapter4 = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiTransactionTotalThisYearTableAdapter();
            this.SuspendLayout();
                        

            //initialize Report            
            initReportDS("fiRepGetFiTransactionsRange", "fiRepGetFiTransactionsRange");
            initReportDS2("FiTransactionTotalBeforeX", "FiTransactionTotalBeforeX");
            initReportDS3("FiTransactionTotalUntilEndDate", "FiTransactionTotalUntilEndDate");
            initReportDS4("FiTransactionTotalThisYear", "FiTransactionTotalThisYear");
            

            dsXTableAdapter.ClearBeforeFill = true;
            dsXTableAdapter2.ClearBeforeFill = true;
            dsXTableAdapter3.ClearBeforeFill = true;
            dsXTableAdapter4.ClearBeforeFill = true;

            // Add controls
            addControlFiscalYear();
            //addControlAccountNoTexBox();
            addControlAccountNameTextBox();
            addControlAccountNoCombobox();
            addControlDateStart();
            addControlDateEnd();                                  

            this.FiscalYearComboBox.SelectedIndexChanged += new System.EventHandler(this.onFiscalYearChangedUpdateStartAndEndDates);
            this.accountNameTextBox.Leave += new System.EventHandler(this.OnAccountNameChangedUpdateAccountNoComboBox);
            
            this.ResumeLayout(false);

            loadReport();
        }

        public void InitReport0702()
        {
            P2CuberryDataSetTableAdapters.fiRepGetFiTransactionsRange02TableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.fiRepGetFiTransactionsRange02TableAdapter();
            //P2CuberryDataSetTableAdapters.FiTransactionTotalBeforeXTableAdapter dsXTableAdapter2 = new ReportViewer.P2CuberryDataSetTableAdapters.FiTransactionTotalBeforeXTableAdapter();
            //P2CuberryDataSetTableAdapters.FiTransactionTotalUntilEndDateTableAdapter dsXTableAdapter3 = new ReportViewer.P2CuberryDataSetTableAdapters.FiTransactionTotalUntilEndDateTableAdapter();
            
            this.SuspendLayout();                        

            //initialize Report            
            initReportDS("fiRepGetFiTransactionsRange02", "fiRepGetFiTransactionsRange02");
            //initReportDS2("FiTransactionTotalBeforeX", "FiTransactionTotalBeforeX");
            //initReportDS3("FiTransactionTotalUntilEndDate", "FiTransactionTotalUntilEndDate");            

            dsXTableAdapter.ClearBeforeFill = true;
            //dsXTableAdapter2.ClearBeforeFill = true;
            //dsXTableAdapter3.ClearBeforeFill = true;            

            // Add controls
            addControlFiscalYear();
            addControlAccountNoTexBox();
            addControlDateStart();
            addControlDateEnd();

            this.FiscalYearComboBox.SelectedIndexChanged += new System.EventHandler(this.onFiscalYearChangedUpdateStartAndEndDates);

            this.ResumeLayout(false);

            loadReport();
        }

        public void InitReport0704()
        {
            P2CuberryDataSetTableAdapters.JournalOneAccountDataTableTableAdapter dsXTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.JournalOneAccountDataTableTableAdapter();

            this.SuspendLayout();

            //initialize Report            
            initReportDS("JournalOneAccountDataTable", "JournalOneAccountDataTable");

            dsXTableAdapter.ClearBeforeFill = true;

            // Add controls
            addControlFiscalYear();
            addControlDateStart();
            addControlDateEnd();
            addControlAccountNameTextBox();
            addControlAccountNoCombobox();
            addControlTransactionStatusCombobox();

            this.accountNameTextBox.Leave += new System.EventHandler(this.OnAccountNameChangedUpdateAccountNoComboBox);
            this.FiscalYearComboBox.SelectedIndexChanged += new System.EventHandler(this.OnAccountNameChangedUpdateAccountNoComboBox);

            this.ResumeLayout(false);

            loadReport();
        }

        public void InitReport0705()
        {
            this.SuspendLayout();

            //initialize Report            
            initReportDS("JournalAllAccountsRangeGroupedDataTable", "JournalAllAccountsRangeGroupedDataTable");

            // Add controls
            addControlFiscalYear();
            addControlDateStart();
            addControlDateEnd();
            addControlAccountNoTexBox();
            addControlTransactionStatusCombobox();            

            this.ResumeLayout(false);

            loadReport();
        }

        public void InitReport0706()
        {
            this.SuspendLayout();

            //initialize Report            
            initReportDS("JournalAllAccountsRangeDataTable", "JournalAllAccountsRangeDataTable");

            // Add controls
            addControlFiscalYear();
            addControlAccountNoTexBox();
            addControlDateStart();
            addControlDateEnd();
            addControlTransactionStatusCombobox();

            this.ResumeLayout(false);
            loadReport();
        }

        public void InitReport0707()
        {
            this.SuspendLayout();

            initReportDS("JournalTransactionHeaderGroupedDataTable", "JournalTransactionHeaderGroupedDataTable");

            // Add controls
            addControlFiscalYear();
            addControlDateStart();
            addControlDateEnd();
            addControlDocumentNoTextBox();
            addControlDescriptionHeaderTextBox();
            addControldescriptionItemTextBox();
            
            this.ResumeLayout(false);
            loadReport();
        }

        #endregion

        #region LocalCuberryReport Preperation Components


        private void initReportDS(string bsDataMemberName, string reportDataSourceName)
        {
            
            // dsXBindingSource            
            dsXBindingSource.DataMember = bsDataMemberName;
            dsXBindingSource.DataSource = this.P2CuberryDataSet;

            reportDataSourceQX.Name = reportDataSourceName;
            reportDataSourceQX.Value = dsXBindingSource;
            this.reportViewer1.LocalReport.DataSources.Add(reportDataSourceQX);            
        }

        private void initReportDS2(string bsDataMemberName2, string reportDataSourceName2)
        {
            // dsXBindingSource            
            dsXBindingSource2.DataMember = bsDataMemberName2;
            dsXBindingSource2.DataSource = this.P2CuberryDataSet;

            reportDataSourceQX2.Name = reportDataSourceName2;
            reportDataSourceQX2.Value = dsXBindingSource2;
            this.reportViewer1.LocalReport.DataSources.Add(reportDataSourceQX2);
        }

        private void initReportDS3(string bsDataMemberName3, string reportDataSourceName3)
        {
            // dsXBindingSource            
            dsXBindingSource3.DataMember = bsDataMemberName3;
            dsXBindingSource3.DataSource = this.P2CuberryDataSet;

            reportDataSourceQX3.Name = reportDataSourceName3;
            reportDataSourceQX3.Value = dsXBindingSource3;
            this.reportViewer1.LocalReport.DataSources.Add(reportDataSourceQX3);
        }

        private void initReportDS4(string bsDataMemberName4, string reportDataSourceName4)
        {
            // dsXBindingSource            
            dsXBindingSource4.DataMember = bsDataMemberName4;
            dsXBindingSource4.DataSource = this.P2CuberryDataSet;

            reportDataSourceQX4.Name = reportDataSourceName4;
            reportDataSourceQX4.Value = dsXBindingSource4;
            this.reportViewer1.LocalReport.DataSources.Add(reportDataSourceQX4);
        }
                
        private void loadReport()
        {
            this.reportViewer1.LocalReport.ReportEmbeddedResource = @"LocalCuberryReport.Reports." + this.ReportTitle + ".rdlc";    
        }

        private void addControlFiscalYear()
        {
            P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter fiFiscalYearTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiFiscalYearTableAdapter();
            System.Windows.Forms.BindingSource fyBindingSource = new System.Windows.Forms.BindingSource(this.components);

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).BeginInit();

            this.FiscalYearComboBox.DataSource = fyBindingSource;
            this.FiscalYearComboBox.DisplayMember = "FiscalYearName";
            this.FiscalYearComboBox.FormattingEnabled = true;
            this.FiscalYearComboBox.Location = new System.Drawing.Point(33, 12);
            this.FiscalYearComboBox.Name = "FiscalYearComboBox";
            this.FiscalYearComboBox.Size = new System.Drawing.Size(166, 21);
            this.FiscalYearComboBox.TabIndex = 1;
            this.FiscalYearComboBox.ValueMember = "FiscalYearID";
            this.splitContainer1.Panel1.Controls.Add(this.FiscalYearComboBox);

            fyBindingSource.DataMember = "FiFiscalYear";
            fyBindingSource.DataSource = this.P2CuberryDataSet;

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).EndInit();
            fiFiscalYearTableAdapter.ClearBeforeFill = true;

            fiFiscalYearTableAdapter.Fill(this.P2CuberryDataSet.FiFiscalYear);
        }

        private void onFiscalYearChangedUpdateStartAndEndDates(object sender, EventArgs e)
        {
            DateTime dateStart = this.DateStartTexBox.Value.Date;
            DateTime dateEnd = this.DateEndTexBox.Value.Date; 

            if (this.FiscalYearComboBox.SelectedIndex > -1)
            {
                DataRowView row = (DataRowView)this.FiscalYearComboBox.SelectedItem;
                dateStart =Convert.ToDateTime(row[2]);
                dateEnd = Convert.ToDateTime(row[3]);

                this.DateStartTexBox.Value = dateStart;
                this.DateEndTexBox.Value = dateEnd;

                ReportParameter dateStartParameter = new ReportParameter("ParameterDateStart", dateStart.ToString());
                ReportParameter dateEndParameter = new ReportParameter("ParameterDateEnd", dateEnd.ToString());

                ReportParameter dateStartFYParameter = new ReportParameter("ParameterFYDateStart", dateStart.ToString());
                ReportParameter dateEndFYParameter = new ReportParameter("ParameterFYDateEnd", dateEnd.ToString());
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { dateStartParameter, dateEndParameter, dateStartFYParameter, dateEndFYParameter });
            }            
        }

        private void addControlAccountType()
        {
            P2CuberryDataSetTableAdapters.FiAccountTypeTableAdapter fiAccountTypeTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiAccountTypeTableAdapter();
            System.Windows.Forms.BindingSource fyBindingSource = new System.Windows.Forms.BindingSource(this.components);

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).BeginInit();

            this.AccountTypeComboBox.DataSource = fyBindingSource;
            this.AccountTypeComboBox.DisplayMember = "FiAccountTypeNameAr";
            this.AccountTypeComboBox.FormattingEnabled = true;
            this.AccountTypeComboBox.Location = new System.Drawing.Point(233, 42);
            this.AccountTypeComboBox.Name = "AccountTypeComboBox";
            this.AccountTypeComboBox.Size = new System.Drawing.Size(166, 21);
            this.AccountTypeComboBox.TabIndex = 1;
            this.AccountTypeComboBox.ValueMember = "FiAccountTypeID";
            this.splitContainer1.Panel1.Controls.Add(this.AccountTypeComboBox);

            fyBindingSource.DataMember = "FiAccountType";
            fyBindingSource.DataSource = this.P2CuberryDataSet;

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).EndInit();
            fiAccountTypeTableAdapter.ClearBeforeFill = true;

            fiAccountTypeTableAdapter.Fill(this.P2CuberryDataSet.FiAccountType );
        }
        
        private void addControlStatusOpen()
        {
            this.StatusOpenCheckBox.AutoSize = true;
            this.StatusOpenCheckBox.Location = new System.Drawing.Point(33, 42);
            this.StatusOpenCheckBox.Name = "StatusOpen";
            this.StatusOpenCheckBox.Size = new System.Drawing.Size(80, 17);
            this.StatusOpenCheckBox.TabIndex = 4;
            this.StatusOpenCheckBox.Text = "Status Open";
            this.StatusOpenCheckBox.UseVisualStyleBackColor = true;
            this.StatusOpenCheckBox.Checked = true;
            this.splitContainer1.Panel1.Controls.Add(this.StatusOpenCheckBox);        
        }
        
        private void addControlStatusBooked()
        {
            this.StatusBookedCheckBox.AutoSize = true;
            this.StatusBookedCheckBox.Location = new System.Drawing.Point(133, 42);
            this.StatusBookedCheckBox.Name = "StatusBooked";
            this.StatusBookedCheckBox.Size = new System.Drawing.Size(80, 17);
            this.StatusBookedCheckBox.TabIndex = 4;
            this.StatusBookedCheckBox.Text = "Status Booked";
            this.StatusBookedCheckBox.UseVisualStyleBackColor = true;
            this.StatusBookedCheckBox.Checked = true;
            this.splitContainer1.Panel1.Controls.Add(this.StatusBookedCheckBox);
        }

        private void addControlMonthComboBox()
        {
            ArrayList aList = new ArrayList();
            int i;

            for (i = 1; i <= 12; i++)
                aList.Add(i);

            //this.MonthComboBox.Items.AddRange(new object[] {"1","2","3","4","5", "6", "7", "8", "9", "10", "11", "12"});
            this.MonthComboBox.DataSource = aList;
            this.MonthComboBox.DisplayMember = "MonthNumber";
            this.MonthComboBox.FormattingEnabled = true;
            this.MonthComboBox.Location = new System.Drawing.Point(233, 12);
            this.MonthComboBox.Name = "MonthComboBox";
            this.MonthComboBox.Size = new System.Drawing.Size(50, 21);
            this.MonthComboBox.TabIndex = 1;
            this.MonthComboBox.ValueMember = "MonthID";
            this.splitContainer1.Panel1.Controls.Add(this.MonthComboBox);
        }

        private void addControlAccountLevelComboBox(int MaxLevel)
        {
            ArrayList aList = new ArrayList();
            int i;

            for (i = 1; i <= MaxLevel; i++)
                aList.Add(i);

            this.AccountLevelComboBox.DataSource = aList;
            this.AccountLevelComboBox.DisplayMember = "AccountLevelNumber";
            this.AccountLevelComboBox.FormattingEnabled = true;
            this.AccountLevelComboBox.Location = new System.Drawing.Point(333, 12);
            this.AccountLevelComboBox.Name = "AccountLevelComboBox";
            this.AccountLevelComboBox.Size = new System.Drawing.Size(50, 21);
            this.AccountLevelComboBox.TabIndex = 1;
            this.AccountLevelComboBox.ValueMember = "AccountLevelComboBoxID";
            this.splitContainer1.Panel1.Controls.Add(this.AccountLevelComboBox);
        }

        private void addControlAccountNoTexBox()
        {
            this.AccountNoTexBox.Location = new System.Drawing.Point(233, 42);
            this.AccountNoTexBox.Name = "AccountNoTexBox";
            this.AccountNoTexBox.Size = new System.Drawing.Size(166, 21);
            this.AccountNoTexBox.TabIndex = 1;
            this.splitContainer1.Panel1.Controls.Add(this.AccountNoTexBox);
        }

        private void addControlDateStart()
        {
            this.DateStartTexBox.Location = new System.Drawing.Point(433, 12);
            this.DateStartTexBox.Name = "DateStartTexBox";
            this.DateStartTexBox.Size = new System.Drawing.Size(200, 20);
            this.DateStartTexBox.TabIndex = 1;
            this.splitContainer1.Panel1.Controls.Add(this.DateStartTexBox);
        }

        private void addControlDateEnd()
        {
            this.DateEndTexBox.Location = new System.Drawing.Point(433, 42);
            this.DateEndTexBox.Name = "DateEndTexBox";
            this.DateEndTexBox.Size = new System.Drawing.Size(200, 20);
            this.DateEndTexBox.TabIndex = 1;
            this.splitContainer1.Panel1.Controls.Add(this.DateEndTexBox);
        }

        private void addControlAccountNameTextBox()
        {            
            accountNameTextBox.Name = "accountNameTextBox";
            accountNameTextBox.Size = new System.Drawing.Size(166, 20);
            accountNameTextBox.TabIndex = 3;

            accountNameTextBox.Location = new System.Drawing.Point(233, 12);
            this.splitContainer1.Panel1.Controls.Add(accountNameTextBox);
        }

        private void addControlTransactionStatusCombobox()
        {

            P2CuberryDataSetTableAdapters.EnterpriseWorkflowStatusTableAdapter enterpriseWorkflowStatusTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.EnterpriseWorkflowStatusTableAdapter();
            System.Windows.Forms.BindingSource fyBindingSource = new System.Windows.Forms.BindingSource(this.components);

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).BeginInit();

            transactionStatusCombobox.DropDownStyle = ComboBoxStyle.DropDownList;
            transactionStatusCombobox.DataSource = fyBindingSource;
            transactionStatusCombobox.DisplayMember = "StatusNameAr";
            transactionStatusCombobox.ValueMember = "StatusID";
            transactionStatusCombobox.FormattingEnabled = true;
            transactionStatusCombobox.Location = new System.Drawing.Point(33, 42);
            transactionStatusCombobox.Name = "transactionStatusCombobox";
            transactionStatusCombobox.Size = new System.Drawing.Size(166, 21);
            transactionStatusCombobox.TabIndex = 2;

            this.splitContainer1.Panel1.Controls.Add(transactionStatusCombobox);

            fyBindingSource.DataMember = "EnterpriseWorkflowStatus";
            fyBindingSource.DataSource = this.P2CuberryDataSet;

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).EndInit();
            
            enterpriseWorkflowStatusTableAdapter.ClearBeforeFill = true;

            this.P2CuberryDataSet.EnterpriseWorkflowStatus.DataSet.EnforceConstraints = false;
            enterpriseWorkflowStatusTableAdapter.Fill(this.P2CuberryDataSet.EnterpriseWorkflowStatus);
 
        }

        private void addControlAccountNoListbox()
        {
            accountNoListBox.SelectionMode = SelectionMode.MultiSimple;

            accountNoListBox.ValueMember = "FiAccountID";
            accountNoListBox.DisplayMember = "FullName";
            accountNoListBox.FormattingEnabled = true;
            accountNoListBox.Location = new System.Drawing.Point(220, 12);
            accountNoListBox.Name = "accountNoCListBox";
            accountNoListBox.Size = new System.Drawing.Size(200, 80);
            accountNoListBox.TabIndex = 4;

            this.splitContainer1.Panel1.Controls.Add(accountNoListBox);
        }

        private void addControlAccountNoCombobox()
        {
            accountNoComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            accountNoComboBox.ValueMember = "FiAccountNo";
            accountNoComboBox.DisplayMember = "FullName";
            accountNoComboBox.FormattingEnabled = true;
            accountNoComboBox.Location = new System.Drawing.Point(233, 42);
            accountNoComboBox.Name = "accountNoComboBox";
            accountNoComboBox.Size = new System.Drawing.Size(166, 21);
            accountNoComboBox.TabIndex = 4;

            this.splitContainer1.Panel1.Controls.Add(accountNoComboBox);
        }

        private void OnAccountNameChangedUpdateAccountNoComboBox(object sender, EventArgs e)
        {
            if (this.FiscalYearComboBox.SelectedIndex == -1 || String.IsNullOrEmpty(this.accountNameTextBox.Text))
                return;

            P2CuberryDataSetTableAdapters.FiAccountTableAdapter fiAccountTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiAccountTableAdapter();
            System.Windows.Forms.BindingSource fyBindingSource = new System.Windows.Forms.BindingSource(this.components);

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).BeginInit();

            accountNoComboBox.DataSource = fyBindingSource;
            DataRowView fiYearRow = (DataRowView)this.FiscalYearComboBox.SelectedItem;
            int fiYear = Convert.ToInt32(fiYearRow["FiscalYearID"].ToString());

            fyBindingSource.DataMember = "FiAccountDataTable";
            fyBindingSource.DataSource = this.P2CuberryDataSet;

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).EndInit();

            fiAccountTableAdapter.ClearBeforeFill = true;
            this.P2CuberryDataSet.FiAccountDataTable.DataSet.EnforceConstraints = false;

            fiAccountTableAdapter.FillByAccountName(this.P2CuberryDataSet.FiAccountDataTable, fiYear, this.accountNameTextBox.Text.Trim());            
        }

        private void OnFiscalYearChangedUpdateAccountNoListBox(object sender, EventArgs e)
        {
            if (this.FiscalYearComboBox.SelectedIndex == -1)
                return;

            P2CuberryDataSetTableAdapters.FiAccountTableAdapter fiAccountTableAdapter = new LocalCuberryReport.P2CuberryDataSetTableAdapters.FiAccountTableAdapter();
            System.Windows.Forms.BindingSource fyBindingSource = new System.Windows.Forms.BindingSource(this.components);

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).BeginInit();

            accountNoListBox.DataSource = fyBindingSource;
            DataRowView fiYearRow = (DataRowView)this.FiscalYearComboBox.SelectedItem;
            int fiYear = Convert.ToInt32(fiYearRow["FiscalYearID"].ToString());

            fyBindingSource.DataMember = "FiAccountDataTable";
            fyBindingSource.DataSource = this.P2CuberryDataSet;

            ((System.ComponentModel.ISupportInitialize)(fyBindingSource)).EndInit();
            
            fiAccountTableAdapter.ClearBeforeFill = true;
            this.P2CuberryDataSet.FiAccountDataTable.DataSet.EnforceConstraints = false;

            fiAccountTableAdapter.Fill(this.P2CuberryDataSet.FiAccountDataTable, fiYear);            

        }

        private void addControlDocumentNoTextBox()
        {
           
            documentNoTextBox.Name = "documentNoTextBox";
            documentNoTextBox.Size = new System.Drawing.Size(166, 20);
            documentNoTextBox.TabIndex = 3;

            documentNoTextBox.Location = new System.Drawing.Point(33, 42);
            //accountName.Location = new Point(33, 42);
            this.splitContainer1.Panel1.Controls.Add(documentNoTextBox);
        }

        private void addControlDescriptionHeaderTextBox()
        {
            
            descriptionHeaderTextBox.Name = "descriptionHeader";
            descriptionHeaderTextBox.Size = new System.Drawing.Size(166, 20);
            descriptionHeaderTextBox.TabIndex = 3;

            descriptionHeaderTextBox.Location = new System.Drawing.Point(233, 12);
            //accountName.Location = new Point(33, 42);
            this.splitContainer1.Panel1.Controls.Add(descriptionHeaderTextBox);
        }

        private void addControldescriptionItemTextBox()
        {
            
            descriptionItemTextBox.Name = "descriptionItem";
            descriptionItemTextBox.Size = new System.Drawing.Size(166, 20);
            descriptionItemTextBox.TabIndex = 3;

            descriptionItemTextBox.Location = new System.Drawing.Point(233, 42);
            //accountName.Location = new Point(33, 42);
            this.splitContainer1.Panel1.Controls.Add(descriptionItemTextBox);
        }

    #endregion


        void DrillthroughEventHandlerR08(object sender, DrillthroughEventArgs e)
        {
            LocalReport localReport = (LocalReport)e.Report;
            
            dsXBindingSource.DataMember = "DataTable8";
            dsXBindingSource.DataSource = this.P2CuberryDataSet;

            reportDataSourceQX.Name = "DataTable8";
            reportDataSourceQX.Value = dsXBindingSource;
            localReport.DataSources.Add(reportDataSourceQX);
            
            //ReportParameter fyParameter = new ReportParameter("ParameterFiscalYear", this.FiscalYearComboBox.GetItemText(FiscalYearComboBox.SelectedItem));
            //ReportParameter monthParameter = new ReportParameter("ParameterMonth", this.MonthComboBox.SelectedValue.ToString());
            //localReport.SetParameters(new ReportParameter[] { fyParameter, monthParameter });
            
            int statusOpen = Convert.ToInt16(this.StatusOpenCheckBox.Checked);
            int statusBooked = Convert.ToInt16(this.StatusBookedCheckBox.Checked);
            //int accountLevel = Convert.ToInt16(this.AccountLevelComboBox.SelectedValue);
            int fiscalYear = Convert.ToInt32(this.FiscalYearComboBox.SelectedValue);

            //foreach (char si in localReport.OriginalParametersToDrillthrough[0].Values[0])
            //    MessageBox.Show(si.ToString());

            
            
            this.dataTable8TableAdapter.Fill(this.P2CuberryDataSet.DataTable8, 8, fiscalYear, 12, 5, statusOpen, statusBooked); //todo: get AccountLevel from XConfig table
        }

        private void reportViewer_Drillthrough(object sender, DrillthroughEventArgs e)
        {
            if (e.Report is ServerReport) return;

            LocalReport localReport = (LocalReport)e.Report;
            // Sales Order Detail local report 
            // takes two datasets
            // Load the Sales Order dataset
            P2CuberryDataSetTableAdapters.DataTable8TableAdapter oAdapter = new P2CuberryDataSetTableAdapters.DataTable8TableAdapter();
            //P2CuberryDataSet.DataTable8DataTable dt8 = oAdapter.GetData(localReport.OriginalParametersToDrillthrough[0].Values[0]);
            //localReport.DataSources.Add(new ReportDataSource("DataTable8", dt8));
            
            //OrderTableAdapter orderAdapter = new Entities.SalesOrderTableAdapters.OrderTableAdapter();
            //SalesOrder.OrderDataTable orderTable = orderAdapter.GetData(localReport.OriginalParametersToDrillthrough[0].Values[0]);
            //localReport.DataSources.Add(new ReportDataSource("SalesOrder", orderTable));
            
        }


    }
}